<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">接种用户ID</label>
                            <div class="layui-input-inline">
                                <input type="text" name="uid" autocomplete="off" class="layui-input">
                            </div>

                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">接种疫苗ID</label>
                            <div class="layui-input-inline">
                                <input type="text" name="did" autocomplete="off" class="layui-input">
                            </div>

                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data1-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>

            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
            </div>
        </script>

        <table class="layui-hide" id="jzTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        var insTb = table.render({
            elem: '#jzTableId',
            url: 'http://110.42.199.36:8081/vaccination/selectAllVac',
            toolbar: '#toolbarDemo',

            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            parseDate:function (res){
                console.log("parseDate")
                console.log(res);
                return {
                    "code":res.status,
                    "msg":res.message,
                    "count":res.total,
                    "data":res.data
                }
            },
            response: {
                statusName: 'status' //规定数据状态的字段名称，默认：code
                ,statusCode: 200 //规定成功的状态码，默认：0
                ,msgName: 'msg' //规定状态信息的字段名称，默认：msg
                ,countName: 'count' //规定数据总数的字段名称，默认：count
                ,dataName: 'data' //规定数据列表的字段名称，默认：data
            },

            cols: [[
                { field: 'uid', title: '接种用户id', width: '120' },
                { field: 'did', title: '接种疫苗id', width: '120' },
                { field: 'time', title: '接种时间', width: '200' },
                { field: 'dose', title: '接种剂次', width: '120' },
                { field: 'vacc_unit', title: '接种单位', width: '200' },
                { field: 'enterprise', title: '生产企业', width: '120' },
                { field: 'batch_number', title: '疫苗批号', width: '120' },
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]]
            // limits: [10, 15, 20, 25, 50, 100],
            // limit: 10,
            // page: true,
            // skin: 'line'
        });

        // 搜索
        // form.on('submit(formSubSearchBook)', function (data) {
        //
        // });
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            result = data.field;
            console.log(result)
            var obj = {
                "uid":parseInt(result.uid)
            };
            //insTb.reload({where: obj,url:'http://110.42.199.36:8081/user/getUserMsgByUid',page : {curr : 1}}, 'data');
            $.ajax({
                type: "POST",
                contentType: 'application/json',
                url: "http://110.42.199.36:8081/vaccination/getVacMsgByUid ",
                data:JSON.stringify(obj),
                dataType: 'json',
                success: function (data) {
                    console.log("成功");
                    console.log(data.data);

                    var res = JSON.stringify(data.data);

                    layer.alert(res, {
                        title: '最终的搜索信息'
                    });
                    table.reload('jzTableId', {
                        where: { //设定异步数据接口的额外参数，任意设
                            uid: '1'

                        }
                        ,page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    }); //只重载数据

                }

            })

            return false;
        });

        form.on('submit(data1-search-btn)', function (data) {
            result = data.field;
            console.log(result)
            var obj = {
                "did":parseInt(result.did)
            };
            //insTb.reload({where: obj,url:'http://110.42.199.36:8081/user/getUserMsgByUid',page : {curr : 1}}, 'data');
            $.ajax({
                type: "POST",
                contentType: 'application/json',
                url: "http://110.42.199.36:8081/vaccination/getVacMsgByDid",
                data:JSON.stringify(obj),
                dataType: 'json',
                success: function (data) {
                    console.log("成功");
                    console.log(data.data);

                    var res = JSON.stringify(data.data);

                    layer.alert(res, {
                        title: '最终的搜索信息'
                    });
                    table.reload('jzTableId', {
                        where: { //设定异步数据接口的额外参数，任意设
                            did: '1'

                        }
                        ,page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    }); //只重载数据

                }

            })

            return false;
        });
        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: 'jz_add.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {

                var index = layer.open({
                    title: '编辑用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: 'jz_edit.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('确认删除吗', function (index) {
                    console.log(obj);
                    console.log(obj.data);
                    console.log(obj.data.did);
                    var didobj = {
                        "did":parseInt(obj.data.did)
                    }
                    console.log(didobj)
                    $.ajax({
                        type: "POST",
                        contentType: 'application/json',
                        url: "http://110.42.199.36:8081/vaccination/deleteVacByDid",
                        data:JSON.stringify(didobj),
                        dataType: 'json',
                        success: function (data) {
                            console.log("成功");
                            console.log(data);
                        }
                    })

                    obj.del();
                    layer.close(index);

                });
            }
        });

    });
</script>

</body>
</html>